Gitlab忘记root用户密码解决办法

您所在的位置:网站首页 gitlab 查看自己权限 Gitlab忘记root用户密码解决办法

Gitlab忘记root用户密码解决办法

2023-04-13 17:40| 来源: 网络整理| 查看: 265

一、Gitlab忘记root用户密码,重置用户密码和查看用户ID号方法 

1、Gitlab查看用户id号的方法1)方法1:通过api接口查询接口查询地址:http://gitlab的url/api/v4/users?username=用户名

比如查看gitlab的root用户id在浏览器页面里直接访问"http://172.16.60.237/api/v4/users?username=root"或者在linux终端命令行里直接通过curl命令进行访问

[root@localhost ~]# curl http://172.16.60.237/api/v4/users?username=root [{"id":1,"name":"Administrator","username":"root","state":"active","avatar_url":"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon","web_url":"http://gitlab.example.com/root"}]

2)方法2:进入gitlab数据库查询  

[root@localhost ~]# gitlab-rails dbconsole psql (10.9) Type "help" for help. gitlabhq_production=> \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges ---------------------+-------------+----------+-------------+-------------+--------------------------------- gitlabhq_production | gitlab | UTF8 | en_US.UTF-8 | en_US.UTF-8 | postgres | gitlab-psql | UTF8 | en_US.UTF-8 | en_US.UTF-8 | template0 | gitlab-psql | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/"gitlab-psql" + | | | | | "gitlab-psql"=CTc/"gitlab-psql" template1 | gitlab-psql | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/"gitlab-psql" + | | | | | "gitlab-psql"=CTc/"gitlab-psql" (4 rows) ## 连接数据库 gitlabhq_production=> \c gitlabhq_production You are now connected to database "gitlabhq_production" as user "gitlab". gitlabhq_production=> select id,name,username from users; id | name | username ----+---------------+---------- 1 | Administrator | root (1 row) ## 查找账户id gitlabhq_production=> select id from users where username = 'root'; id ---- 1 (1 row) ==============================================================================================

2、忘记Gitlab的root用户密码的重置方法

如果忘记了Gitlab的root用户密码,则可以在服务器上面直接修改数据:

[root@localhost ~]# gitlab-rails console production #然后以此执行下面命令(需要提前查询用户的id号) ...> user = User.where(id: 1).first ...> user.password = 'secret_pass' ...> user.password_confirmation = 'secret_pass' ...> user.save!

例如重置root用户密码为root@123,root用户id为1  

[root@localhost ~]# gitlab-rails console production DEPRECATION WARNING: Passing the environment's name as a regular argument is deprecated and will be removed in the next Rails version. Please, use the -eoption instead. (called from require at bin/rails:4) -------------------------------------------------------------------------------- GitLab: 12.2.0 (1c1d47c5974) GitLab Shell: 9.3.0 PostgreSQL: 10.9 -------------------------------------------------------------------------------- Loading production environment (Rails 5.2.3) irb(main):001:0> user = User.where(id: 1).first => # irb(main):002:0> user.password = 'root@123' => "root@123" irb(main):003:0> user.password_confirmation = 'root@123' => "root@123" irb(main):004:0> user.save! Enqueued ActionMailer::DeliveryJob (Job ID: e562694d-2a1b-4bad-843b-d8567ac51077) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", # => true irb(main):005:0> quit

 

-----------------------------------------------------------书山有路勤为径,学海无涯苦作舟------------------------------------------------------------- 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3